package com.pet.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.entity.PetAnimal;
import com.pet.entity.PetDonation;
import com.pet.service.PetAnimalService;
import com.pet.service.PetDonationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * @author cxq
 *
 *
 * @date 2023/11/13
 */
@RestController
@RequestMapping("petDonation")
@Api(value = "提供数据显示所需的接口",tags = "宠物捐赠管理")
public class PetDonationController extends ApiController {
    @Resource
    private PetDonationService petDonationService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param petDonation 查询实体
     * @return 所有数据
     */
    @ApiOperation("分页接口")
    @GetMapping
    public R selectAll(Page<PetDonation> page, PetDonation petDonation) {
        return success(this.petDonationService.page(page, new QueryWrapper<>(petDonation)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过id查询数据")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.petDonationService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param petDonation 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("插入数据")
    public R insert(@RequestBody PetDonation petDonation) {
        return success(this.petDonationService.save(petDonation));
    }

    /**
     * 修改数据
     *
     * @param petDonation 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody PetDonation petDonation) {
        return success(this.petDonationService.updateById(petDonation));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.petDonationService.removeByIds(idList));
    }
}
